﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MVCProject.Model;
using MVCProject.BLL;

namespace MVCProject.API.Controllers
{
    [ApiAuthorize]
    public class MenusController : ApiController
    {
        // GET: api/Menus
        public ResultData<List<MenusDto>> Get()
        {
            //用户菜单  rid
            var auth = RequestContext.RouteData.Values["auth"] as AuthInfo;
            var rid = int.Parse(auth.Roles);

            ResultData<List<MenusDto>> result = new ResultData<List<MenusDto>>();   

            AuthorityBll bll = new AuthorityBll();
            var auths = bll.Query().Where(a => a.roleID == rid);

            var menus = from a in auths
                        select new MenusDto { 
                            MenuID= a.menuID,
                            MenuName=a.Menus.menuName,
                            Url= a.Menus.url,
                            Icon= a.Menus.icon,
                            ParentID= a.Menus.parentID,
                            LastTime =a.Menus.lastTime
                        };

            result.code = 1;
            result.msg = "ok";
            result.data = menus.ToList();
            return result;
        }

        // GET: api/Menus/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Menus
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/Menus/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/Menus/5
        public void Delete(int id)
        {
        }
    }
}
